package 重温_Java并发基础.并发编程的基础;

import java.lang.management.ManagementFactory;
import java.lang.management.ThreadInfo;
import java.lang.management.ThreadMXBean;

/**
 * 查看一个main函数里面到底包含有多少条线程
 *
 * @author idea
 * @data 2019/4/28
 */
public class Lab01 {

    public static void main(String[] args) {
        //获取线程管理的MXBean
        ThreadMXBean threadMXBean=ManagementFactory.getThreadMXBean();

        //仅仅获取线程的堆栈和线程信息
        ThreadInfo[] threadInfos=threadMXBean.dumpAllThreads(false,false);
        for (ThreadInfo threadInfo : threadInfos) {
            System.out.println(threadInfo.getThreadId()+" : "+threadInfo.getThreadName());
        }

    }
}
